﻿Public Class AddUser

    Private Sub AddUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loademp()
        loadgroup()
    End Sub
    Private Sub loademp()
        cboemp.DisplayMember = "emp_name"
        cboemp.ValueMember = "emp_id"
        cboemp.DataSource = cmd.ExecuteDataTable("SELECT emp_id,emp_name FROM Employee_tbl")
    End Sub
    Private Sub loadgroup()
        cbogroup.DisplayMember = "User_type"
        cbogroup.ValueMember = "User_type_id"
        cbogroup.DataSource = cmd.ExecuteDataTable("SELECT user_Type_id,user_type FROM User_Type_tbl ORDER BY User_Type_Id DESC")
    End Sub

    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        If txtname.Text.Trim = "" Then
            MessageBox.Show("Username can't be empty")
            txtname.Focus()
            Exit Sub
        End If
        If txtpwd.Text.Trim = "" Then
            MessageBox.Show("Password can't be empty")
            txtpwd.Focus()
            Exit Sub
        End If
        cmd.Parameters("@name") = txtname.Text
        cmd.Parameters("@pwd") = txtpwd.Text
        cmd.Parameters("@emp") = cboemp.SelectedValue
        cmd.Parameters("@group") = cbogroup.SelectedValue
        cmd.ExecuteNonQuery("INSERT INTO User_tbl VALUES(null,@group,@name,@pwd,@emp,1)")
        MessageBox.Show("Add New User Sucess")
    End Sub
End Class